# /usr/bin/python3
# coding=utf-8
# @Time:2025/11/13 13:41
# @Author: cc

from common.report_add_img import add_img_2_report
from config.driver_config import DriverConfig
import pytest


@pytest.fixture ( )
def driver() :
    global get_driver
    get_driver = DriverConfig ( ).driverconfig ( )
    yield get_driver
    get_driver.quit ( )


# 内置的勾子函数
@pytest.hookimpl (tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call) :
    # 获取钩子方法的调用结果,并赋值给变量out
    out = yield
    # 从钩子方法的调用结果中获取测试报告
    # 1、获取测试结果
    report = out.get_result ( )
    report.description = str (item.function.__doc__)
    if report.when == "call" :
        if report.failed :
            # 失败了就截图
            add_img_2_report (get_driver, '失败截图', need_sleep=False)
